﻿#region usings
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SilverlightContrib.Controls;
#endregion
namespace InsuranceAdjuster.Views {
    public partial class BranchView : UserControl {
        private ViewModels.BranchViewModel _viewModel;
        private bool _firstCheck = true;
        public BranchView() {
            _viewModel = ((ViewModels.ViewModelLocator)(App.Current.Resources["Locator"])).Branch;
            
            InitializeComponent();


            var Test1 = lblBranchName.FontFamily;
            var Test2 = lblBranchName.FontSize;
            var Test3 = lblBranchName.FontStretch;
            var Test4 = lblBranchName.FontStyle;
            var Test5 = lblBranchName.FontWeight;
        }

        private void OnReloadBranchStyles(object sender, RoutedEventArgs e) {
            _viewModel.BranchStyle.Load();
        }
        private void OnSave(object sender, RoutedEventArgs e) {
            _viewModel.OnSaveBranch();
        }


        private void colorPicker_SelectedColorChanging(object sender, SilverlightContrib.Controls.SelectedColorEventArgs e)
        {

        }

        private void BackColor_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            colorPicker.DataContext = backgroundColorRect;
            colorPicker.SelectedColor = _viewModel.BranchStyle.BackgroundBrush.Color;
            colorPicker.Visibility = Visibility.Visible;
        }

        private void ForeColor_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            colorPicker.DataContext = foregroundColorRect;
            colorPicker.SelectedColor = _viewModel.BranchStyle.ForegroundBrush.Color;
            colorPicker.Visibility = Visibility.Visible;
        }

        private void colorPicker_SelectedColorChanged(object sender, SelectedColorEventArgs e)
        {
            if(!_firstCheck)
            {
                if (colorPicker.DataContext == foregroundColorRect)
                {
                    _viewModel.BranchStyle.ForegroundBrush = new SolidColorBrush(e.SelectedColor);

                    colorPicker.Visibility = Visibility.Collapsed;
                }
                else if (colorPicker.DataContext == backgroundColorRect)
                {
                    _viewModel.BranchStyle.BackgroundBrush = new SolidColorBrush(e.SelectedColor);

                    colorPicker.Visibility = Visibility.Collapsed;
                }
             }

            _firstCheck = false;
        }

    }
}
